package com.bruce.codeFactory.enumDemo;

import java.util.logging.Logger;

/**
 * @author luotuan
 * @Description
 * @create 2019-05-05 21:25
 **/
public enum Game {
    ROCK("石头"), PAPER("剪刀"), SCISSORS("布");
    public static Logger log = Logger.getLogger(Game.class.toString());

    enum Result {
        WIN("赢"), DRAW("平局"), LOSE("输");
        private String name;

        Result(String name) {
            this.name = name;
        }

        public String getName() {
            return this.name;
        }
    }

    private String name;
    private static Result[][] gameResults = {
            {Result.DRAW, Result.WIN, Result.LOSE},
            {Result.LOSE, Result.DRAW, Result.WIN},
            {Result.WIN, Result.LOSE, Result.DRAW}
    };

    Game(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public Result complete(Game game) {
        return gameResults[this.ordinal()][game.ordinal()];
    }

    public static void main(String[] args) {
        log.info("-------------游戏开始----------");
        for (int i = 0; i < 20; i++) {
            Game game1 = EnumUtil.random(Game.class);
            Game game2 = EnumUtil.random(Game.class);
            log.info(game1.getName() + " VS " + game2.getName() + ": " + game1.complete(game2).getName());
        }
    }
}
